package com.example.music.adapter;

import static android.graphics.Color.parseColor;

import android.graphics.Color;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.music.R;

import java.util.List;

public class LyricsAdapter extends RecyclerView.Adapter<LyricsAdapter.LyricViewHolder> {

    private List<String> lyricsList;
    private int highlightedPosition = -1;

    public static class LyricViewHolder extends RecyclerView.ViewHolder {
        public TextView textView;

        public LyricViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.tv_lyric_line);
        }
    }

    public LyricsAdapter(List<String> lyricsList) {
        this.lyricsList = lyricsList;
    }

    @NonNull
    @Override
    public LyricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_lyric, parent, false);
        return new LyricViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull LyricViewHolder holder, int position) {
        String lyric = lyricsList.get(position);
        holder.textView.setText(lyric);

        // 设置高亮样式
        if (position == highlightedPosition) {
            holder.textView.setTextColor(parseColor("#007AFF")); // 改变字体颜色
            holder.textView.setTextSize(Typeface.BOLD, 20); // 可选：加大字号
        } else {
            holder.textView.setTextColor(Color.GRAY);
            holder.textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        }
    }

    @Override
    public int getItemCount() {
        return lyricsList.size();
    }

    public void setHighlightedPosition(int position) {
        highlightedPosition = position;
        notifyDataSetChanged();
    }
}
